package top.loonglove.utils;

/**
 * @author : xgl
 * @version : 0.0.1
 * @date :2021/7/15 0:37
 */
public final class StringUtils {
    /**
     * 检验base是否以start字符串开头end字符串结尾的并且start和end不相交
     * @param base 待匹配字符串
     * @param start 前缀
     * @param end 后缀
     * @return base是否以start开头end结尾
     */
    public static boolean withStartAndEnd(String base,String start,String end){
        return (start.length()+end.length()<base.length())&&base.startsWith(start)&&base.endsWith(end);
    }

    /**
     * 格式化前缀和后缀
     * @param base 基字符串
     * @param start 前缀
     * @param end 后缀
     * @return 格式化后的字符串
     */
    public static String replaceStartAndEnd(String base,String start,String end){
        if (withStartAndEnd(base,start,end)){
            return base.substring(start.length(),base.length()-end.length());
        }else {
            throw new IndexOutOfBoundsException();
        }
    }
}
